package com.rytx.web.controller.ysp;

import com.rytx.common.core.controller.BaseController;
import com.rytx.common.core.domain.AjaxResult;
import com.rytx.system.domain.ysp.ArtCommonConfig;
import com.rytx.system.service.ArtCommonConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/system/artCommonConfig")
@Api(value = "ArtCommonConfigController", tags = "艺术通用配置管理")
public class ArtCommonConfigController extends BaseController {
    @Autowired
    private ArtCommonConfigService artCommonConfigService;

    @GetMapping("/getAllConfigs")
    @ApiOperation(value = "获取所有配置", notes = "获取所有艺术通用配置")
    public List<ArtCommonConfig> getAllConfigs() {
        return artCommonConfigService.getAllConfigs();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取配置", notes = "根据ID获取艺术通用配置")
    public ArtCommonConfig getConfigById(@PathVariable Long id) {
        return artCommonConfigService.getConfigById(id);
    }

    @PostMapping()
    @ApiOperation(value = "创建配置", notes = "创建新的艺术通用配置")
    public AjaxResult createConfig(@RequestBody ArtCommonConfig config) {
        config.setCreateTime(new Date());
        config.setUpdateTime(new Date());
        return AjaxResult.success(artCommonConfigService.createConfig(config));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新配置", notes = "根据ID更新艺术通用配置")
    public AjaxResult updateConfig(@RequestBody ArtCommonConfig config) {
        config.setCreateTime(new Date());
        config.setUpdateTime(new Date());
        return AjaxResult.success(artCommonConfigService.updateConfig(config));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除配置", notes = "根据ID删除艺术通用配置")
    public void deleteConfig(@PathVariable Long id) {
        artCommonConfigService.deleteConfig(id);
    }

    @PostMapping("/search")
    @ApiOperation(value = "搜索配置", notes = "根据条件搜索艺术通用配置")
    public List<ArtCommonConfig> searchConfigs(@RequestBody ArtCommonConfig config) {
        return artCommonConfigService.searchConfigs(config);
    }
}
